<script setup>
import { ref, reactive } from 'vue'
import { userInfo } from './loginData'
// do not use same name with ref
const form = reactive({
  loginName: '',
  password: '',
})

const onSubmit = () => {
  console.log('submit!')

  let loginSuccess = false
  userInfo.forEach((item) => {
    if (form.loginName === item.loginName) {
      if (form.password === item.password) {
        loginSuccess = true
        return false
      }
    }
  })

  if (loginSuccess) {
    alert('登录成功')
  } else {
    alert('登录失败')
  }

}

</script>

<template>
  <div class="login">
    <el-form :model="form" label-width="120px">
      <el-form-item label="用户名">
        <el-input v-model="form.loginName" />
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password" type="password" show-password />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">登录</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped>
.login {
  display: grid;
  max-width: 600px;
  margin: 60px auto;
}
</style>
